/*
 * Copyright (c) 2021 Futurewei Technologies, Inc.
 *
 * clang2mpl is licensed under Mulan PSL v2.
 * You can use this software according to the terms and conditions of the Mulan
 * PSL v2. You may obtain a copy of Mulan PSL v2 at:
 *
 *     http://license.coscl.org.cn/MulanPSL2
 *
 * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY
 * KIND, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO
 * NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. See the
 * Mulan PSL v2 for more details.
 */
// RUN: %clang2mpl --ascii --verify %s -- -Wno-unused-value --target=aarch64-linux-elf
// RUN: cat %m | %FileCheck %s

// CHECK: type $u0 <union {
// CHECK-NEXT:   @p <* i32>,
// CHECK-NEXT:   @i i32}>
union u0 {
  int *p;
  int i;
};

void foo(int *a, int b) {
  // CHECK: LOC 2 [[#SLINE: @LINE + 2 ]]{{$}}
  // CHECK-NEXT: var %s <$u0>
  union u0 s = {a};
  // CHECK: LOC 2 [[#TLINE: @LINE + 2 ]]{{$}}
  // CHECK-NEXT: var %t <$u0>
  union u0 t = {(int *)0};
  // CHECK: LOC 2 [[#ULINE: @LINE + 2 ]]{{$}}
  // CHECK-NEXT: var %u <$u0>
  union u0 u = {.p = a};
  // CHECK: LOC 2 [[#VLINE: @LINE + 2 ]]{{$}}
  // CHECK-NEXT: var %v <$u0>
  union u0 v = {.p = (int *)0};
  // CHECK: LOC 2 [[#WLINE: @LINE + 2 ]]{{$}}
  // CHECK-NEXT: var %w <$u0>
  union u0 w = {.i = b};
  // CHECK: LOC 2 [[#XLINE: @LINE + 2 ]]{{$}}
  // CHECK-NEXT: var %x <$u0>
  union u0 x = {.i = 4};

  // CHECK: LOC 2 [[#SLINE]]{{$}}
  // CHECK-NEXT: dassign %s 1 (dread a64 %a)
  // CHECK: LOC 2 [[#TLINE]]{{$}}
  // CHECK-NEXT: dassign %t 1 (constval u64 0)
  // CHECK: LOC 2 [[#ULINE]]{{$}}
  // CHECK-NEXT: dassign %u 1 (dread a64 %a)
  // CHECK: LOC 2 [[#VLINE]]{{$}}
  // CHECK-NEXT: dassign %v 1 (constval u64 0)
  // CHECK: LOC 2 [[#WLINE]]{{$}}
  // CHECK-NEXT: dassign %w 2 (dread i32 %b)
  // CHECK: LOC 2 [[#XLINE]]{{$}}
  // CHECK-NEXT: dassign %x 2 (constval i32 4)
}
